package com.mgblog.web.interceptor;

import java.util.Map;

import com.mgblog.vo.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
 * 自定义拦截器
 * @author Administrator
 *
 */
public class MGInterceptor extends AbstractInterceptor{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		// 取得请求相关的ActionContext实例  
        ActionContext ctx = invocation.getInvocationContext();  
        Map map = ctx.getSession();
        User loginUser = (User) map.get("loginUser");
        // 如果没有登陆,都返回重新登陆  
        if(null == loginUser){
        	System.out.println("没有登陆");
        	return "index";
        }
        return invocation.invoke();
	}

}
